
function value_function(i,obj){
	var str = '';
	if(i.delete_flag == 0){
		str = "<button onclick='hideInfo(this)' class='button button-small border-sub'>隐藏</button> ";
	}else{
		str = "<button onclick='showInfo(this)' class='button button-small border-sub'>显示</button> "
	}
	return "<button onclick='operate_modify(this)' class='button button-small border-sub'>修改</button> "+
	"<button onclick='operate_search(this)' class='button button-small border-sub'>子菜单</button> "+
	"<button onclick='deleteInfo(this)' class='button button-small border-sub'>删除</button> "+ str;
}

function sunccessReturn(){
	closeAll();
	$("#init-table").tableAdaptor();
}

function beforeFunc(){
	$("#sub-name,#sub-category").val("");
}

function deleteInfo(obj){
	lcomfirm('是否确定删除该字典？',function(){
		var id = $("#init-table").data("cache")[$(obj).parent().parent().attr("tag")].id;
		commonAjax("DELETE",localUrl+"/dictionary?id="+id, "",function(){
			tip("删除成功");
			setTimeout(function(){
				closeAll();
				$("#init-table").tableAdaptor();
			},1000)
		});
	});
}

function hideInfo(obj){
	lcomfirm('是否确定隐藏该字典？',function(){
		var id = $("#init-table").data("cache")[$(obj).parent().parent().attr("tag")].id;
		commonAjax("PUT",localUrl+"/dictionary", {id:id,delete_flag:1},function(){
			setTimeout(function(){
				closeAll();
				$("#init-table").tableAdaptor();
			},1000)
		});
	});
}

function showInfo(obj){
	lcomfirm('是否确定显示该字典？',function(){
		var id = $("#init-table").data("cache")[$(obj).parent().parent().attr("tag")].id;
		commonAjax("PUT",localUrl+"/dictionary", {id:id,delete_flag:0},function(){
			setTimeout(function(){
				closeAll();
				$("#init-table").tableAdaptor();
			},1000)
		});
	});
}

/**
 * 修改
 * @returns
 */
function operate_modify(obj){
	debugger
	var id = $("#init-table").data("cache")[$(obj).parent().parent().attr("tag")].code;
	var config = {
			'url':"/dictionary?id="+id
	}
	detail_get_restall("#table-detail-info",config);
	openWindow("修改数据字典","#table-detail-info","250px");
	$("#table-detail-info input,#table-detail-info select").val("");
}
/**
 * 查看子菜单
 */

var conditin =[];
var param = {};



function operate_search(obj){
	var code = $("#init-table").data("cache")[$(obj).parent().parent().attr("tag")].code;
	if(code != null){
		if($("#return_back_div").is(":hidden")){
			$("#return_back_div").show();
		}
		var condition_data = {};
		condition_data.page = $("#kkpager .curr").html();
		condition_data.data = param;
		
		condition_data.name =$("#init-table").data("cache")[$(obj).parent().parent().attr("tag")].name;
		condition_data.code = $("#father-dictionary").attr("code");
		condition_data.p_code = $("#init-table").data("cache")[$(obj).parent().parent().attr("tag")].code;
		condition_data.p_dictionary_name = $("#init-table").data("cache")[$(obj).parent().parent().attr("tag")].dictionary_name;
		
		conditin.push(condition_data);
		
		// 显示名字
		var show_name = "";
		for(var i=0;i<conditin.length;i++){
			if(conditin[i].name!="")
				show_name += conditin[i].name+"-";
		}
		
		$("#father-dictionary").html(show_name);
		$("#father-dictionary").attr("code",$("#init-table").data("cache")[$(obj).parent().parent().attr("tag")].code);
		$("#father-dictionary").attr("p_dictionary_name",$("#init-table").data("cache")[$(obj).parent().parent().attr("tag")].dictionary_name);
		$("#p_code_add").attr("value",$("#init-table").data("cache")[$(obj).parent().parent().attr("tag")].code);
		$("#p_dictionary_name_add").attr("value",$("#init-table").data("cache")[$(obj).parent().parent().attr("tag")].dictionary_name);
		$("#parent_key_input").val(code);
		param = {"p_code":code };
		$("#init-table").data("params", param);
		$("#init-table").tableAdaptor();
	}
}

$(function(){
	
	$("#return_back").click(function(){
		var obj = conditin.pop();
		$("#parent_key_input").val(obj.data.p_code);
		$("#sub-name-alias").val("");
		$("#sub_category").val("");
		param = obj.data;
		if(conditin.length<1){
			$("#return_back_div").hide();
			$("#father-dictionary").attr("code","");
			$("#parent_key_input").val("");
			param.isOnlyP=1;
			$("#p_code_add").attr("value",'');
			$("#p_dictionary_name_add").attr("value",'');
		}else{
			$("#p_code_add").attr("value",obj.p_code);
			$("#p_dictionary_name_add").attr("value",obj.p_dictionary_name);
		}
		// 显示名字
		var show_name = "";
		for(var i=0;i<conditin.length;i++){
			if(conditin[i].name!="")
				show_name += conditin[i].name;
		}
		$("#father-dictionary").html(show_name);
		$("#father-dictionary").attr("p_code",obj.p_code);
		$("#init-table").data("params", param);
		$("#init-table").tableAdaptor();
	})
	
})